home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / dsp / fft / fteyaltr.z / fteyaltr / fft1.c < prev    next >
C/C++ Source or Header  |  1991-09-01  |  2KB  |  79 lines

  1. /*--------------------------- fft1.c ---------------------------------- */
  2. /*                                    */
  3. /* Author:    Eyal Lebedinsky                        */
  4. /* Date:    May 1990                        */
  5. /* Version:    31 August 1991                        */
  6. /*                                    */
  7. /* Measure the fft() time. NOTE that on UNIX and other multiprogramming    */
  8. /* systems you will need to replace time() with a cpu timing function.    */
  9. /*                                    */
  10. /*--------------------------------------------------------------------- */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <time.h>
  15.  
  16. extern void FAR fft ();
  17.  
  18. #define N 256
  19.  
  20. short        NEAR x[N] = {0};
  21. short        NEAR qf[N/2+1] = {0};
  22. static short    xx[N];
  23.  
  24. static void
  25. test_once (flag)
  26. int    flag;
  27. {
  28.     memcpy (x, xx, sizeof (x));
  29.     if (flag)
  30.         fft();
  31. }
  32.  
  33. static long
  34. test_all (flag, l)
  35. int    flag;
  36. long    l;
  37. {
  38.     long    t;
  39.  
  40.     t = time (0);
  41.     while (--l)
  42.         test_once (flag);
  43.  
  44.     return (time (0) - t);
  45. }
  46.  
  47. main()
  48. {
  49.     long    i, t1, t2;
  50.  
  51.     for (i = 0; i < N; ++i)
  52.         xx[i] = 1024 * (i % 32);    /* saw-tooth */
  53.  
  54.     for (i = 100L;;) {
  55.         printf ("fft1> trying %ld times, ", i);
  56.         t1 = test_all (1, i);
  57.         t1 -= (t2 = test_all (0, i));
  58.         if (t1 >= 50L)
  59.             break;
  60.         if (t1 < 4)
  61.             i *= 5L;
  62.         else
  63.             i = (i * 50L) / (t1 - 1);
  64.         printf ("too fast (only %ld+%ld seconds)\n", t1, t2);
  65.     }
  66.     printf ("good (%ld+%ld seconds)\n", t1, t2);
  67.  
  68.     printf ("fft1> time per fft(): ");
  69.     t2 = (t1 * 10000L) / i;
  70.     if (t2 > 100)
  71.         printf ("%ld.%ld millisec\n", t2 / 10, t2 % 10);
  72.     else {
  73.         t2 = (t1 * 1000000L) / i;
  74.         printf ("%ld microsec\n", t2);
  75.     }
  76.  
  77.     exit (0);
  78. }
  79.